# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=dsme
pkgver=0.84.3
pkgrel=0
_commit_dbusglib="d42176ae4763e5288ef37ea314fe58387faf2005"
pkgdesc="Device State Management Entity"
url="https://github.com/sailfishos/dsme"
arch="all"
license="LGPL-2.1-only"
depends_dev="
	cryptsetup-dev
	libiphb-dev
	libngf-dev
	"
makedepends="$depends_dev
	autoconf
	automake
	libtool
	"
subpackages="$pkgname-dev $pkgname-openrc"
source="https://github.com/sailfishos/dsme/archive/$pkgver/dsme-$pkgver.tar.gz
	https://github.com/sailfishos-mirror/dbus-glib/archive/$_commit_dbusglib/dbus-glib-$_commit_dbusglib.tar.gz
	0001-correct-paths.patch
	0002-disable-werror.patch
	dsme.initd
	dsme.confd
	"
options="!check" # Only test comes from dbus-glib and fails

prepare() {
	default_prepare

	rmdir dbus-gmain
	mv "$srcdir/dbus-glib-$_commit_dbusglib" dbus-gmain
}

build() {
	./autogen.sh
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--exec_prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-static \
		--disable-poweron-timer \
		--disable-systemd \
		--disable-upstart \
		--disable-validatorlistener \
		--enable-pwrkeymonitor \
		--enable-abootsettings \
		--enable-usewheel
	make
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm644 reboot-via-dsme.sh -t "$pkgdir"/etc/profile.d/

	install -Dm755 "$srcdir"/dsme.initd "$pkgdir"/etc/init.d/dsme
	install -Dm644 "$srcdir"/dsme.confd "$pkgdir"/etc/conf.d/dsme

	# Remove installed tests
	rm -r "$pkgdir"/opt

	mkdir -p "$pkgdir"/usr/share/dbus-1/system.d/
	mv "$pkgdir"/etc/dbus-1/system.d/* "$pkgdir"/usr/share/dbus-1/system.d/
}

sha512sums="
b0aa18d1aec6704bb63b508402211380de61a0bf8057f385c2c3cfcd37dbb7cbfc569cdd7f20524c0a41f49bb868b6aef9f7adf232d8a16b625589b63d3d6bb0  dsme-0.84.3.tar.gz
665cd6395ee0ea14086ba30188c62a72697b3f63484681e18fc7f54109c9aca162f2e33aa2fa4d45287c6c0b590e81ca310c143dac0232cd5887692cdaf51256  dbus-glib-d42176ae4763e5288ef37ea314fe58387faf2005.tar.gz
063ce9f2bd13fb2bd05ab9cd11544265eb5378562ee1fbed1cfa65d2345d092cfcff69f57589d3914005c31a00a58f3993cc13b59615ebe0f48458ba478d8772  0001-correct-paths.patch
2b18c6affaefa786358c07480968fd744370c48452c05e969cc8b26cba5307279ce51f782f42778fbd597bf29ec3d90b7b1ee4d182e8ab41675d1070be2f1954  0002-disable-werror.patch
786971b4a8f9cff0b66db658d9b8a2c4ceaaf1c5baa4b62346b9e0a2ab6f46ff3225a60678cb7ddd78e4e9e70fbe41432581e32ebccfa4174375dc79fea49a84  dsme.initd
b841282b96110ec59a7aa539db0737327b09549d55c78dc4b2c3b28b4a6ad1facf015b3175cb6d3a38f13e47aa6314ef3dc1514a4e60dd653a97409ec54ba706  dsme.confd
"
